<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue Light Switch</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        .light-switch-container {
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .light-switch-button {
            font-size: 18px;
            padding: 10px 20px;
            cursor: pointer;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            transition: background-color 0.3s;
            margin-bottom: 10px;
        }
        .light-switch-button:hover {
            background-color: #45a049;
        }
        .light-bulb {
            width: 150px;
            height: auto;
            transition: opacity 0.3s;
        }
        .lit {
            opacity: 1;
        }
        .unlit {
            opacity: 0.5;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="light-switch-container">
            <button @click="toggleLight" class="light-switch-button">
                {{ isLightOn ? '关灯' : '开灯' }}
            </button>
            <img :src="lightSrc" :class="{ lit: isLightOn, unlit: !isLightOn }" alt="Light bulb" class="light-bulb">
        </div>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                isLightOn: false,
            },
            computed: {
                lightSrc() {
                    return this.isLightOn ? 'img/off.jpg' : 'img/on.jpg';
                },
            },
            methods: {
                toggleLight() {
                    this.isLightOn = !this.isLightOn;
                },
            },
        });
    </script>
</body>
</html>